// 钉钉 机器人api

var express = require('express');
var router = express.Router();
const dingtalkPush = require('../utils/dingtalkPush/index')
var handlers = require('../utils/handler/index');
var dujitang = require('./dujitangData');

// 设置推送任务
// handlers.setSchedule('0 0 18 * * 1-5', () => {
//     dingtalkPush.sendMsg('多粉最大彩票投注站', '下班了,快点收拾东西走人！', {
//         "at": {
//             "isAtAll": true
//         }
//     })
// })
// handlers.setSchedule('0 30 8 * * 1-6', () => {
//     dingtalkPush.sendMsg('吴彦祖和他的跟班', dujitang.getDujitang())
//     dingtalkPush.sendMsg('多粉最大彩票投注站', dujitang.getDujitang())
// })


// 接受钉钉信息
router.post('/receive',function(req, res, next) {
    // 接收数据
    const { text, conversationTitle } = req.body
    const content  = text.content.trim()
    if (content.includes('最帅的')) {
        dingtalkPush.sendMsg(conversationTitle, '黄奕铭是最帅的')
    }else if(content.includes('鸡汤') || content.includes('毒鸡汤')) {
        dingtalkPush.sendMsg(conversationTitle, dujitang.getDujitang())
    }else if (['福利彩票', '福彩', '双色球'].findIndex(ele => content.includes(ele)) !== -1) {
        if (['随机', '来一注', '机选', '一注'].findIndex(ele => content.includes(ele)) !== -1) {
            handlers.sendLottery(1,1,conversationTitle)
        } else {
            handlers.sendLotteryRes(1,conversationTitle)
        }
    }else if (['体育彩票', '体彩', '大乐透', '乐透'].findIndex(ele => content.includes(ele)) !== -1) {
        if (['随机', '来一注', '机选', '一注'].findIndex(ele => content.includes(ele)) !== -1) {
            handlers.sendLottery(2,1,conversationTitle)
        } else {
            handlers.sendLotteryRes(2,conversationTitle)
        }
    } else if (['cnm', 'cnmch', '你妈', '草', '狗逼', '傻逼'].findIndex(ele => content.includes(ele)) !== -1) {
        dingtalkPush.sendMsg(conversationTitle, 'cnmch')
    } else {
    }
    res.send('received')
});

module.exports = router;
